/***************
 * Home Saved Searches Panel
 */
AIR2.Home.SavedSearches = function() {
    return new AIR2.UI.Panel({
        colspan: 1,
        title: 'Saved Searches',
        cls: 'air2-home-ss',
        iconCls: 'air2-icon-savedsearch',
        showTotal: true,
        storeData: AIR2.Home.SSDATA,
        itemSelector: '.air2-home-ss-row',
        url: AIR2.HOMEURL+'/savedsearch',
        tpl: new Ext.XTemplate(
            '<table>' +
            '<tr><th>SEARCH</th><th class="right">SHARED</th></tr>' +
            '<tpl for="."><tr class="air2-home-ss-row">' +
              '<td><a class="name" ' +
                'href="'+AIR2.HOMEURL+'/savedsearch/{ssearch_uuid}">{ssearch_name}</a></td>' +
              '<td align="right">{[AIR2.Format.bool(values.ssearch_public_flag)]}</td>' +
            '</tr></tpl>' +
            '</table>',
            {
                compiled: true,
                disableFormats: true
            }
        ),
        editModal: {
            allowAdd: false,    // only via search page
            width: 650,
            items: {
                xtype: 'air2liveeditor',
                url: AIR2.HOMEURL+'/savedsearch',
                sortField: 'ssearch_cre_dtim',
                sortDir: 'DESC',
                pageSize: 25,
                allowEdit: true,
                allowDelete: true,
                hideButtons: true,
                editForm: {
                    labelAlign: 'top',
                    layout: 'column',
                    items: [
                        {
                            xtype: 'container',
                            columnWidth: .70,
                            layout: 'form',
                            // TODO it would be nice to use the remotetext class here
                            // but since the name already exists, we get false positive
                            // on initial edit.
                            items: [{
                                xtype: 'textfield',
                                hideLabel: true,
                                name: 'ssearch_name',
                                maxLength: 255,
                                width: 400
                            }]
                        },
                        {
                            xtype: 'container',
                            columnWidth: .30,
                            layout: 'form',
                            items:[{
                                xtype: 'checkbox',
                                hideLabel: true,
                                name: 'ssearch_public_flag',
                                boxLabel: "Shared"
                            }]
                        }
                        // TODO project picker #1410
                    ]
                },
                tpl: new Ext.XTemplate(
                    '<div class="air2-savedsearch-item">' +
                      '<table><tr>' +
                        '<td class="name"><a class="name" ' +
                        'href="'+AIR2.HOMEURL+'/savedsearch/{ssearch_uuid}">{ssearch_name}</a></td>' +
                        '<td class="who">{[AIR2.Format.userName(values.CreUser, true)]}</td>' +
                        '<td class="flag">Shared: {[AIR2.Format.bool(values.ssearch_public_flag)]}</td>' +
                        '<td class="meta">' +
                          '<button class="air2-rowedit"></button>' +
                          '<button class="air2-rowdelete"></button>' +
                        '</td>' +
                      '</tr></table>'+
                    '</div>',
                    { compiled: true, disableFormats: true }
                )
            }
        }
    });
}
